package com.my.study.mapstruct;

import com.my.study.mapstruct.assembler.OrderAssembler;
import com.my.study.mapstruct.converter.OrderConverter;
import com.my.study.mapstruct.dao.OrderDO;
import com.my.study.mapstruct.dto.OrderDTO;
import com.my.study.mapstruct.entity.Order;
import org.junit.Test;

import java.util.Collections;

/**
 * 测试 DTO <——> Entity <——> DO 之间的转化
 *
 *
 * @author: yidujun
 * @create: 2021/06/23 15:55
 */
public class AssemblerOrConverterTest {

    @Test
    public void test01() {
        OrderAssembler instance = OrderAssembler.INSTANCE;
        Order order = new Order();
        order.setOrderId(1L);
        order.setOrderName("裤子");
        System.out.println(order);

        OrderDTO orderDTO = instance.toDTO(order);
        System.out.println(orderDTO);


        Order toEntity = instance.toEntity(orderDTO);
        System.out.println(toEntity);
    }

    @Test
    public void test02() {
        OrderConverter instance = OrderConverter.INSTANCE;

        OrderDO orderDO = new OrderDO();
        orderDO.setOrderId(1L);
        orderDO.setOrderName("T");
        orderDO.setNums(Collections.singletonList(3));
        System.out.println(orderDO);

        Order order = instance.toEntity(orderDO);
        System.out.println(order);
    }

}
